﻿using System;
using System.IO;
namespace Maticsoft.DBUtility
{
    /// <summary>
    /// 日志帮助类
    /// </summary>
    public class LogHelper
    {
        private LogHelper()
        {
        }

        private static readonly log4net.ILog logger = log4net.LogManager.GetLogger("App.Logging");

  

        /// <summary>
        /// 初始化LOG4NET引擎
        /// </summary>
        public static void SetConfig()
        {
            log4net.Config.DOMConfigurator.Configure();
        }

        /// <summary>
        /// 记录信息
        /// </summary>
        /// <param name="info">信息</param>
        public static void Log(string info)
        {
            if (logger.IsInfoEnabled)
            {
                logger.Info(info);
            }
        }

        /// <summary>
        /// 记录异常
        /// </summary>
        /// <param name="info">信息</param>
        /// <param name="se">异常类</param>
        public static void Error(string info, Exception se)
        {
            if (logger.IsErrorEnabled)
            {
                logger.Error(info, se);
            }
        }

        public static void Error(string info)
        {
            if (logger.IsErrorEnabled)
            {
                logger.Error(info);
            }
        }

        /// <summary>
        /// 记录警告
        /// </summary>
        /// <param name="info"></param>
        public static void Warn(string info)
        {
            if (logger.IsWarnEnabled)
            {
                logger.Warn(info);
            }
        }

        /// <summary>
        /// 记录调试信息
        /// </summary>
        /// <param name="info"></param>
        public static void Debug(string info)
        {
            if (logger.IsDebugEnabled)
            {
                logger.Debug(info);
            }
        }

        /// <summary>
        /// 获得真正的日志
        /// </summary>
        /// <returns></returns>
        public static log4net.ILog GetLogger()
        {
            return logger;
        }
    }
}